package com.dataimport.service.impl;

import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dataimport.entity.sourceentity.ECardAccountInfo;
import com.dataimport.entity.targetentity.ECardInfo;
import com.dataimport.service.ECardAccountInfoService;
import com.dataimport.mapper.ECardAccountInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class ECardAccountInfoServiceImpl extends ServiceImpl<ECardAccountInfoMapper, ECardAccountInfo> implements ECardAccountInfoService{

    @Autowired
    private ECardAccountInfoMapper eCardAccountInfoMapper;

    @Override
    public void dealWithECardInfo() {
        //开启数据库2
        DynamicDataSourceContextHolder.push("mysql2");

        List<ECardAccountInfo> eCardAccountInfos = eCardAccountInfoMapper.selectList(null);
        List<ECardInfo> eCardInfos = eCardAccountInfos.stream().parallel()
                .filter(new Predicate<ECardAccountInfo>() {
                    @Override
                    public boolean test(ECardAccountInfo eCardAccountInfo) {
                        return true;
                    }
                })
                .map(new Function<ECardAccountInfo, ECardInfo>() {
                    @Override
                    public ECardInfo apply(ECardAccountInfo eCardAccountInfo) {
                        ECardInfo eCardInfo = new ECardInfo();
                        eCardInfo.setECardId(eCardAccountInfo.getYktkh());
                        eCardInfo.setUserCode(eCardAccountInfo.getBh());
                        return eCardInfo;
                    }
                })
                .collect(Collectors.toList());
        eCardInfos.forEach(System.out::println);
        DynamicDataSourceContextHolder.poll();
    }
}




